package com.zaofan.service;

import com.zaofan.dao.HotelInfoDao;
import com.zaofan.dao.HotelOrderRecordDao;
import com.zaofan.exception.ServiceException;
import com.zaofan.mobile.bean.HotelInfo;
import com.zaofan.mobile.bean.HotelOrderRecord;

import java.util.List;

/**
 * Created by Administrator on 2016/12/20.
 */
public class HotelService {

    private HotelInfoDao hotelInfoDao = new HotelInfoDao();

    private HotelOrderRecordDao hotelOrderRecordDao = new HotelOrderRecordDao();


    public HotelInfo findOpenHotelByHotelNo(String no) {
        return  hotelInfoDao.findOpenHotelByHotelNo(no);
    }

    public void incScanByHotelNo(String no) {
        hotelInfoDao.incScanByHotelNo(no);
    }


    public void incOrderByHotelNo(String no) {
        hotelInfoDao.incOrderByHotelNo(no);
    }

    public void addOrder(String hotelNo, String orderNo, String mobile) {
        HotelOrderRecord hotelOrderRecord = new HotelOrderRecord();
        hotelOrderRecord.setOrderNo(orderNo);
        hotelOrderRecord.setHotelNo(hotelNo);
        hotelOrderRecord.setUserMobile(mobile);
        hotelOrderRecordDao.addOrder(hotelOrderRecord);
    }

    public void deleteUserAddress(String id) {
        hotelInfoDao.deleteUserAdderss(id);
    }

    public void deleteUserAddressByOpenId(String openid) {
        hotelInfoDao.deleteUserAdderssByOpenId(openid);
    }

    public void addHotel(String hotelNo,int addressId) throws ServiceException {
        List<HotelInfo> hotelInfos = hotelInfoDao.findHotelByHotelNo(hotelNo);
        if (hotelInfos.size() >= 1) {
            throw new ServiceException("该酒店编号已经存在");
        }

        hotelInfoDao.createHotel(hotelNo, addressId);
    }

}
